import React from 'react';
import styles from './index.less';
import {useModel} from "umi"
import {useState} from "react"
export default (props:any) => {
 
  let [mobile, setMobile] = useState('15323807318');
  let [password, setPassword] = useState('123456');

  let {isLogin,doLogin}=useModel('user',model=>({isLogin:model.isLogin,doLogin:model.doLogin}))
  console.log('isLogin.....',isLogin)
  
  async function loginClick(){
    if (!/^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013-8])|(18[0,5-9]))\d{8}$/.test(mobile)){
      alert('请输入正确的手机号');
      return;
    }
    if (!password){
      alert('请输入正确的密码');
      return;
    }
    let result = await doLogin({mobile, password});
    console.log('result...', result);
   if(result){
     console.log( props.history);
     
      props.history.push('/main/cart')
   }
  }
  
  return (
    <div className={styles.login}>
      <img src={require('@/media/a.png')} alt=""/>
      <input type="text" placeholder="请输入你的手机号" value={mobile} onChange={(e)=>setMobile(e.target.value)}/>
      <input type="text" placeholder="请输入你的密码"  value={password} onChange={(e)=>setPassword(e.target.value)}/>
      <button onClick={loginClick}>登陆</button>
    </div>
  );
}
